package com.enen.demo.service.impl;

import com.enen.demo.bean.Category;
import com.enen.demo.dao.CategoryDao;
import com.enen.demo.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private CategoryDao categoryDao;

    @Override
    public void saveOrUpdate(Category category) {
        if(category.getId() == null){
            categoryDao.save(category);
        }else{
            categoryDao.update(category);
        }
    }

    @Override
    public List<Category> findAll() {
        return categoryDao.selectAll();
    }

    @Override
    public Category findCategoryById(long id) {
        return categoryDao.selectById(id);
    }


    @Override
    public void removeCategory(long id) {
        categoryDao.delete(id);
    }


}
